﻿using Bmz.Studio.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bmz.Studio.EntityFramework
{
    public partial class PersonMap:StudioEntityTypeConfiguration<Person>
    {
        public PersonMap()
        {
            this.ToTable("Person");
            this.HasKey(p => p.Id);
            this.Property(p => p.Name).HasMaxLength(10).IsRequired();
            this.Property(p => p.Description).HasMaxLength(100).IsRequired();
            this.Property(p => p.Phone).HasMaxLength(11).IsRequired();
            this.Property(p => p.Address).HasMaxLength(50).IsRequired();
            this.Property(p => p.Qq).HasMaxLength(10).IsRequired();
            this.Property(p => p.Birthday).IsRequired();
            this.Property(p => p.Email).IsRequired();
            this.Property(p => p.Website).HasMaxLength(200);
            this.Property(p => p.Position).HasMaxLength(50);


            this.HasOptional(p => p.About)
                .WithRequired(q => q.Person)
                .WillCascadeOnDelete(true);

            this.HasMany(p => p.Works)
                .WithRequired(q => q.Person)
                .HasForeignKey(s=>s.PersonId)
                .WillCascadeOnDelete(true);

            this.HasMany(p => p.Resumes)
                .WithRequired(q => q.Person)
                .HasForeignKey(s => s.PersonId)
                .WillCascadeOnDelete(true);

            this.HasMany(p => p.Portfolios)
                .WithRequired(q => q.Person)
                .HasForeignKey(s => s.PersonId)
                .WillCascadeOnDelete(true);

            this.HasOptional(p => p.Contact)
                .WithRequired(q => q.Person)
                .WillCascadeOnDelete(true);
        }
    }
}
